<?php
/***************************************************************
*  Copyright notice
*
*  (c) 2007-2008 Starbugs (univis2typo3@googlegroups.com)
*  All rights reserved
*
*  This script is part of the TYPO3 project. The TYPO3 project is
*  free software; you can redistribute it and/or modify
*  it under the terms of the GNU General Public License as published by
*  the Free Software Foundation; either version 2 of the License, or
*  (at your option) any later version.
*
*  The GNU General Public License can be found at
*  http://www.gnu.org/copyleft/gpl.html.
*  A copy is found in the textfile GPL.txt and important notices to the license
*  from the author is found in LICENSE.txt distributed with these scripts.
*
*
*  This script is distributed in the hope that it will be useful,
*  but WITHOUT ANY WARRANTY; without even the implied warranty of
*  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
*  GNU General Public License for more details.
*
*  This copyright notice MUST APPEAR in all copies of the script!
***************************************************************/
/**
 * Module: Web>UnivIS2Typo3
 *
 * Description:
 *
 * Notice: 
 *
 *  
 * @author	Starbugs <univis2typo3@googlegroups.com>
 */

require_once($BACK_PATH.'template.php');
require_once(t3lib_extMgm::extPath('univis2typo3').'/mod1/configuration/class.configuration.persons.php');
require_once(t3lib_extMgm::extPath('univis2typo3').'/mod1/configuration/class.configuration.lectures.php');
require_once(t3lib_extMgm::extPath('univis2typo3').'/mod1/configuration/class.configuration.theses.php');
require_once(t3lib_extMgm::extPath('univis2typo3').'/mod1/configuration/class.configuration.publications.php');
require_once(t3lib_extMgm::extPath('univis2typo3').'/mod1/configuration/class.configuration.projects.php');

class Configuration
{
	var $content;
	var $persons;
	var $lectures;
	var $theses;
	var $publications;
	var $projects;

	function renderContent($id)
	{
		$result = $this->checkPlugin($id);
		
		if ($result == 'univis2typo3_pi1')
		{
			$this->persons 	= new ConfigurationPersons();
			$content = $this->persons->renderContent($id);
		}
		else if ($result == 'univis2typo3_pi2')
		{
			$this->publications = new ConfigurationPublications();
			$content = $this->publications->renderContent($id);
		}
		else if ($result == 'univis2typo3_pi3')
		{
			$this->projects = new ConfigurationProjects();
			$content = $this->projects->renderContent($id);
		}
		else if ($result == 'univis2typo3_pi4')
		{
			$this->lectures = new ConfigurationLectures();
			$content = $this->lectures->renderContent($id);
		}
		else if ($result == 'univis2typo3_pi5')
		{
			$this->theses	= new ConfigurationTheses();
			$content = $this->theses->renderContent($id);
		}
		else if ($result == 'pi0')
		{
			$content = "Please select either a page where the persons plugin or the lectures plugin is inserted";
			print_r($_GET);
		}
		
		echo $content;
	}
	
	function checkPlugin($id)
	{
		$selection	= "DISTINCT list_type";
		$from		= "
					`tt_content` 
					";
		    $where 	= "pid = ".$id;

		$groupby	= "";
		$orderby	= "";
		$limit 		= "";

		$query = $GLOBALS['TYPO3_DB']->SELECTquery(
			$selection,   			// SELECT
			$from,				// FROM
			$where,				// WHERE
			$groupby,	    		// GROUP BY
			$orderby,			// ORDER BY
			$limit				// LIMIT
		);
		$res = $GLOBALS['TYPO3_DB']->sql(TYPO3_db, $query);
		$out = array ();
			
		echo mysql_error();
		
		$isIn = 'pi0';
		
		while ($row = mysql_fetch_assoc($res)) 
		{
			if (in_array('univis2typo3_pi1', $row))
			{
				$isIn = 'univis2typo3_pi1';
				break;
			}
			if (in_array('univis2typo3_pi2', $row))
			{
				$isIn = 'univis2typo3_pi2';
				break;
			}
			if (in_array('univis2typo3_pi3', $row))
			{
				$isIn = 'univis2typo3_pi3';
				break;
			}
			if (in_array('univis2typo3_pi4', $row))
			{
				$isIn = 'univis2typo3_pi4';
				break;
			}
			if (in_array('univis2typo3_pi5', $row))
			{
				$isIn = 'univis2typo3_pi5';
				break;
			}
		}
		return $isIn;
	}
}
?>
